// 云函数入口文件
const cloud = require('wx-server-sdk')
const mysql = require('mysql2/promise')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
  var studentID = event.studentID;
  var name = event.name;
  var phone = event.phone;
  var grade = event.grade;
  var specialities = event.specialities;
  var address = event.address;
  var assisant = event.assisant;
  var password=event.password;
  try{
    const connection = await mysql.createConnection({
      host:"47.115.22.254",
      port:3306,
      database: "EPMS",
      user: "root",
      password: "1234"
    })
    var sql = 'INSERT INTO SUSER(studentID,name,grade,password,specialities,address,assisant,phone,statue,identity) VALUES("' + studentID + '","' + name + '","' + grade + '","' + password + '","' + specialities + '","' + address + '","' + assisant + '","' + phone +'","1","1");';
    // await connection.execute('INSERT INTO SUSER(studentID,name,grade,specialities,address,assisant,phone) VALUES("123","gg","net","net","bb","zl","159202020")');
    await connection.execute(sql);
    conection.end()
    return "successful"
  } catch (err) {
    return err
  }
}
